import { useEventListener } from "@nsb/common-tools/dist/hooks/useEventListener";
import { Classifier } from "./Classifier";

export namespace SmallScreen {
  export enum ScreenClassify {
    Small = 1,
    Normal = 2,
  }
  const rules: Classifier.IRule<ScreenClassify>[] = [{
    kind: ScreenClassify.Small,
    predicate: () => window.screen.width <= 500 || window.screen.height <= 500
  }, {
    kind: ScreenClassify.Normal,
    predicate: () => true
  }]

  export function use(): boolean {
    const [kind, fire] = Classifier.use({ rules });
    useEventListener(window, 'resize', fire);
    return kind === ScreenClassify.Small;
  }
}

